package com.ybkj.daijia.server.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ybkj.daijia.server.serializer.DateTimeSerialize;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 优惠劵规则
 *
 * @author Shine
 */
public class CouponRule extends Base {

    public static final int COUPONRULE_STATUS_NOTSTART = 0;
    public static final int COUPONRULE_STATUS_ONUSING = 1;
    public static final int COUPONRULE_STATUS_OVERDUE = 2;
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @JsonIgnore
    private String title;//标题

    @JsonIgnore
    private String code;//编码

    @JsonIgnore
    @JsonSerialize(using = DateTimeSerialize.class)
    private Date start;// 开始时间

    @JsonSerialize(using = DateTimeSerialize.class)
    private Date end;//结束时间

    private BigDecimal money;// 金额

    @JsonIgnore
    private Long companyId;

    @JsonIgnore
    private boolean lapsed;//是否失效

    @JsonIgnore
    private List<Coupon> coupons;

    @JsonIgnore
    private Integer timeStatus; //0未开始 1使用中 2过期;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public boolean isLapsed() {
        return lapsed;
    }

    public void setLapsed(boolean lapsed) {
        this.lapsed = lapsed;
    }

    public List<Coupon> getCoupons() {
        return coupons;
    }

    public void setCoupons(List<Coupon> coupons) {
        this.coupons = coupons;
    }

    public Integer getTimeStatus() {
        if (start.getTime() > System.currentTimeMillis()) {
            return COUPONRULE_STATUS_NOTSTART;
        } else if (end.getTime() < System.currentTimeMillis()) {
            return COUPONRULE_STATUS_OVERDUE;
        } else {
            return COUPONRULE_STATUS_ONUSING;
        }
    }

    public void setTimeStatus(Integer timeStatus) {
        this.timeStatus = timeStatus;
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

}
